package com.mall.shopping.services.navigation;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContentItem;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static com.mall.shopping.constant.GlobalConstants.HEADER_PANEL_ID;

/**
 * @description: 导航栏显示
 * @author wxy
 * @date 2022-01-20 14:03
 * @version 1.0
 */
@Service
public class IContentServiceImpl implements IContentService {


    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;
    @Override
    public NavListResponse queryNavList() {
        NavListResponse navListResponse = new NavListResponse();
        try {
            List<PanelContentItem> panelContentItems = panelContentMapper.selectPanelContentAndProductWithPanelId(HEADER_PANEL_ID);
            //对象转化
            List<PanelContentDto> panelContentDtos = contentConverter.panelContents2Dto(panelContentItems);
            //执行成功
            navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            navListResponse.setPannelContentDtos(panelContentDtos);

        }catch (Exception e){
            e.printStackTrace();
            navListResponse.setCode(ShoppingRetCode.DB_EXCEPTION.getCode());
            navListResponse.setMsg(ShoppingRetCode.DB_EXCEPTION.getMessage());
        }


            return navListResponse;
    }
}
